package dao.imp;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import dao.ICommentDAO;
import domain.Comment;

public class CommentDAO extends HibernateDaoSupport implements ICommentDAO {

	@Override
	public void addComment(Comment comment) {
		this.getHibernateTemplate().save(comment);
	}

	@Override
	public void deleteComment(Comment comment) {
		this.getHibernateTemplate().delete(comment);
	}

	@Override
	public List<Comment> getAllComments() {
		String hql = "from Comment";
		return (List<Comment>)this.getHibernateTemplate().find(hql);
	}

	@Override
	public Comment getCommentByID(String id) {
		return (Comment) this.getHibernateTemplate().get(Comment.class, id);
	}

	@Override
	public List<Comment> getCommentsByTitle(String title) {
		String hql = "from Comment where title = '"+title+"'";
		return this.getHibernateTemplate().find(hql);
	}

	@Override
	public void updateComment(Comment comment) {
		this.getHibernateTemplate().update(comment);
	}

}
